package com.ideabove.radio.module;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

import com.ideabove.radio.MainActivity;
import com.ideabove.radio.R;

public abstract class ModuleAbs implements ModuleInterface{
	MainActivity activity;
	public static ProgressDialog progressDialog;
	
	
	public static void showProgressDialog(Context context, String title, String message){
		if(progressDialog != null){
			progressDialog.cancel();
		}
		progressDialog = ProgressDialog.show(context, title, message);		
		
	}
	
	public static void hideProgressDialog(){
		
		if(progressDialog != null){						
			progressDialog.dismiss();
		}
	}
	
	protected void init(MainActivity activity){
		this.activity = activity;
	}
	
	// 자식이 필요하면 구현..
	protected void showMd(){}
	protected void hideMd(){}	
	protected void backMd(){}
	

	@Override
	public void show() {
		// TODO Auto-generated method stub
		if (activity.mOrientation == Configuration.ORIENTATION_LANDSCAPE) {			
			return;
		}
		
		View view = (View)activity.findViewById(R.id.flipper_layout);
		view.setVisibility(View.VISIBLE);
		
		view.setOnTouchListener(new View.OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				// 인터셉트~~
				return true;
			}
		});
		
		View btn_top_left_btn_wrap = (View)activity.findViewById(R.id.btn_top_left_btn_wrap);
		btn_top_left_btn_wrap.setVisibility(View.VISIBLE);
		View btn_top_right_btn_wrap = (View)activity.findViewById(R.id.btn_top_right_btn_wrap);
		btn_top_right_btn_wrap.setVisibility(View.VISIBLE);
		
		showMd();
	}

	
	@Override
	public void hide() {
		// TODO Auto-generated method stub
		if(activity.toast == null){
			activity.toast = Toast.makeText(activity.getApplicationContext(), "이전 화면을 다시 보고 싶으시면\n" +
					"상단에 'bonosound'로고를 누르세요", Toast.LENGTH_SHORT);
		}else{
			activity.toast.cancel();
			activity.toast = Toast.makeText(activity.getApplicationContext(), "이전 화면을 다시 보고 싶으시면\n" +
					"상단에 'bonosound'로고를 누르세요", Toast.LENGTH_SHORT);
		}
		
			
		int offsetX = 0;
		int offsetY = 100;
		activity.toast.setGravity(Gravity.CENTER, offsetX, offsetY);
		activity.toast.show();
		
		View btn_top_left_btn_wrap = (View)activity.findViewById(R.id.btn_top_left_btn_wrap);
		btn_top_left_btn_wrap.setVisibility(View.GONE);
		View btn_top_right_btn_wrap = (View)activity.findViewById(R.id.btn_top_right_btn_wrap);
		btn_top_right_btn_wrap.setVisibility(View.GONE);		
		
		View view = (View)activity.findViewById(R.id.flipper_layout);
		view.setVisibility(View.GONE);
		
		hideMd();
	}

	@Override
	public void back() {
		// TODO Auto-generated method stub				
		hideProgressDialog();
	    if (activity != null && activity.mOrientation != Configuration.ORIENTATION_LANDSCAPE) {
	    	backMd();
	    }
	}

	@Override
	public boolean isVisible() {
		// TODO Auto-generated method stub		
		View view = (View)activity.findViewById(R.id.flipper_layout);		
		return (view.getVisibility() == View.VISIBLE) ? true : false;
	}
	
}
